package com.ltg.framework.es.utils;

import co.elastic.clients.elasticsearch.core.SearchResponse;
import co.elastic.clients.elasticsearch.core.search.Hit;

import java.util.ArrayList;
import java.util.List;

/**
 * @Version 1.0
 * @Author LTG
 * @ClassName SearchResponseUtils
 * @Date 2023/11/15 19:14
 */
public class SearchResponseUtils {

    public static <T> List<T> getSource(SearchResponse<T> searchResponse) {
        List<T> sources = new ArrayList<>();
        List<Hit<T>> hits = searchResponse.hits().hits();
        for (Hit<T> hit : hits) {
            sources.add(hit.source());
        }
        return sources;
    }


}
